package com.bootdo.task.util;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.app.service.AssigningTaskService;
import com.bootdo.common.domain.DictDO;
import com.bootdo.common.service.DictService;
import com.bootdo.goods.domain.TGoodsAllocationDO;
import com.bootdo.goods.service.TGoodsAllocationService;
import com.bootdo.output.service.OutStorageDetailService;
import com.bootdo.output.service.OutStorageService;
import com.bootdo.provider.domain.GoodsInfoDO;
import com.bootdo.provider.domain.ProviderInfoDO;
import com.bootdo.provider.service.DriverService;
import com.bootdo.provider.service.GoodsInfoService;
import com.bootdo.provider.service.ProviderInfoService;
import com.bootdo.shop.domain.ShopDO;
import com.bootdo.shop.service.ShopService;
import com.bootdo.staff.domain.StaffUserDO;
import com.bootdo.staff.service.StaffUserService;
import com.bootdo.task.domain.TTaskDO;
import com.bootdo.task.domain.TTaskDatilDO;
import com.bootdo.task.service.TTaskDatilService;
import com.bootdo.task.service.TTaskService;

/**
 * 包装类型 使其数据字典值对应上名称
 * @author wlst
 *
 */
@Service
public class PackageTaskType {

	@Autowired
	private ProviderInfoService providerInfoService;
	
	@Autowired
	private GoodsInfoService goodsInfoService;
	
	@Autowired
	private  TGoodsAllocationService tGoodsAllocationService;
	
	@Autowired
	private StaffUserService staffUserService;
	
	@Autowired
	private ShopService shopService;
	
	@Autowired
	private DictService dictService;
	
	/**
	 * 包装分拣任务清单
	 * @param do1
	 * @return
	 */
	public TTaskDO packageTTaskPojo(TTaskDO do1) {
		//执行人 加急 状态 供应商 门店
		ProviderInfoDO  pro = providerInfoService.get(do1.getTaskSupplierId());
		do1.setSupplierName(pro.getProviderFname());//供应商名称
		StaffUserDO userName = null;
		if(do1.getTaskName()!= null) {
			userName=	staffUserService.get(Long.valueOf(do1.getTaskName()));
			do1.setUserName(userName.getStaffName());//用户名
		}
		ShopDO shop = shopService.get(Long.valueOf(do1.getTaskShopId()));
		do1.setTaskShopName(shop.getShopName());//门店
		Map<String, Object> map = new HashMap<>();
		map.put("value", do1.getTaskGrade());
		DictDO dict = dictService.list(map).get(0);
		do1.setGradeName(dict.getName());//加急
		map.put("value",do1.getTaskStatus());
		dict  = dictService.list(map).get(0); 
 		do1.setStatusName(dict.getName());//状态
 		pro = null;
 		userName = null;
 		shop = null;
 		dict = null;
 		map.clear();
 		System.gc();
		return do1;
	}

	/**
	 * 包装分拣任务详情
	 * @param do1
	 * @return
	 */
	public TTaskDatilDO packageTTaskDatilPojo(TTaskDatilDO tTaskDatilDO) {
		Map<String, Object> map = new HashMap<>();
		map.put("value", tTaskDatilDO.getTdStatus());
		DictDO dict = dictService.list(map).get(0);
		tTaskDatilDO.setStatusName(dict.getName());
	 
		GoodsInfoDO	g=goodsInfoService.get(tTaskDatilDO.getTdGid());
		tTaskDatilDO.setgName(g.getGoodsName()); 
		String	location = tTaskDatilDO.getTdInitalAllocation();
		String	tdArea = location.substring(0, 1)+"区";
		String	tdRow = location.substring(1, 3)+"排";
		String	tdLevel = location.substring(3, 4)+"层";
		String	tdNum = location.substring(4)+"号";
		tTaskDatilDO.setTdArea(tdArea);
		tTaskDatilDO.setTdRow(tdRow);
		tTaskDatilDO.setTdLevel(tdLevel);
		tTaskDatilDO.setTdNum(tdNum);
		 g = null;//商品信息
		 location = null;
		 tdArea = null;
		 tdRow = null;
		 tdLevel = null;
		 tdNum = null;
		 System.gc();
		return tTaskDatilDO;
	}
	
}
